package com.example.osixaffairssystem.service.impl;

import com.example.osixaffairssystem.domain.PageBean;
import com.example.osixaffairssystem.domain.model.Course;
import com.example.osixaffairssystem.mapper.CourseMapper;
import com.example.osixaffairssystem.service.CourseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor
public class CourseServiceImpl implements CourseService {

    final CourseMapper courseMapper;

    @Override
    public List<Course> list() {
        return courseMapper.list();
    }

    @Override
    public PageBean<Course> listToPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        Page<Course> p = (Page<Course>) courseMapper.list();

        return new PageBean<>(p.getTotal(), p.getResult());
    }

    @Override
    public Integer insert(Course course) {
        courseMapper.insert(course);
        return course.getId();
    }

    @Override
    public void update(Course course) {
        courseMapper.update(course);
    }

    @Override
    public void delete(List<Integer> ids) {
        courseMapper.delete(ids);
    }
}
